using System.Collections.Generic;
using UnityEngine;

public class Bezier
{
    public static Vector3 BezierMethod_Point(float t, List<Vector3> forceList)
    {
        if (forceList.Count < 2)
            return forceList[0];
        List<Vector3> temp = new List<Vector3>();
        for (int i = 0; i < forceList.Count - 1; i++)
        {
            Debug.DrawLine(forceList[i], forceList[i + 1], Color.black, 1000);
            //Debug.Log(forceList[i] + " " + forceList[i + 1]);
            Vector3 proportion = (1 - t) * forceList[i] + t * forceList[i + 1];
            temp.Add(proportion);
        }
        return BezierMethod_Point(t, temp);
    }

    public static Vector3 BezierMethod_Tangent(float t, List<Vector3> forceList)
    {
        if (forceList.Count < 2)
            return forceList[0];
        List<Vector3> temp = new List<Vector3>();
        for (int i = 0; i < forceList.Count - 1; i++)
        {
            //Debug.DrawLine(forceList[i], forceList[i + 1], Color.black, 1000);
            //Debug.Log(forceList[i] + " " + forceList[i + 1]);
            Vector3 proportion = (1 - t) * forceList[i] + t * forceList[i + 1];
            temp.Add(proportion);
        }
        if (temp.Count == 2)
        {
            return temp[1] - temp[0];
        }
        return BezierMethod_Tangent(t, temp);
    }
}
